<?php
//=======================================
//###################################
// Kayako Web Solutions
//
// Source Copyright 2001-2004 Kayako Infotech Ltd.
// Unauthorized reproduction is not allowed
// License Number: $%LICENSE%$
// $Author: vshoor $ ($Date: 2006/03/23 01:49:40 $)
// $RCSfile: upgrade_step3.php,v $ : $Revision: 1.9 $ 
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
//
//###################################
//=======================================


if (!defined("INSWIFT")) {
	// File being called directly, end it
	trigger_error("Unable to process $PHP_SELF", E_USER_ERROR);
}

displayHeader();

if ($dbCore->connected)
{
	upgrade_updateVersion(SWIFTVERSION);

	// ======= SETTINGS =======
	require_once ("./includes/functions_settings.php");

	importSettingsFromFile("./setup/includes/swift.settings.xml", false, true);

	require_once ("./includes/functions_template.php");

	$result = updateTemplatesFromFile(dirname(__FILE__)."/../includes/swift.templates.xml", false, false);
	if (!$result)
	{
		trigger_error("ERROR: Could not insert all templates. $sqlcount - $insertedchunks", E_USER_ERROR);
	}

	foreach ($result["categorylist"] as $key=>$val)
	{
		displayStatus("Updating Template Category: ".$val, true);
	}

	foreach ($result["templatelist"] as $key=>$val)
	{
		displayStatus("Updating Template: ".$val, true);
	}

	// ======= LANGUAGE PHRASES =======
	require_once ("./includes/functions_language.php");
	mergeLanguageFromFile(1, "./setup/includes/swift.language.xml", false, true);
	displayStatus("Updated Master Language", true);

	rebuildAllCoreCaches();

	// Empty the cache directory
	if ($handle = opendir('./cache/')) {
		while (false !== ($file = readdir($handle))) { 
			if ($file != "." && $file != ".." && $file != "index.html") { 
				@unlink("./cache/".$file); 
			}
		}

		closedir($handle); 
	}

	$_SWIFT["error"] = true;

} else {
	$_SWIFT["error"] = true;
}

displayMessage("Your version is now up to date");
displayFooter();
?>